#!/usr/bin/env bash

# ----------------------------------------------------------------------
# Filename:   04-security-nrjb.sh
# Version:    1.0
# Date:       2020/07/29
# Author:     Lz
# Email:      lz843723683@gmail.com
# History：     
#             Version 1.0, 2020/07/30
# Function:   测试NRJB 防火墙和selinux
# Out:        
#              0 => TPASS
#              1 => TFAIL
#              other=> TCONF
# ----------------------------------------------------------------------

## TODO : 测试收尾清除工作
#
ScrtClean_FTNRJB(){
	return $TPASS
}


## TODO: 调用程序退出函数
#    In: $1 => 调用脚本结果值
ScrtExit_FTNRJB(){
        # 调用退出函数，其中调用了clean相关函数
	Exit_FTLIB ${1}
}


## TODO: 用户界面
#
ScrtUSAGE_FTNRJB(){
	USAGE_FTLIB "NRJB - 防火墙和selinux"
}


## TODO : 测试前的初始化 
#  Out  : 
#         0 => TPASS
#         1 => TFAIL
#         other=> TCONF
ScrtInit_FTNRJB(){
        # 调用初始化函数
	Init_FTLIB "ScrtClean_FTNRJB"
        # 调用用户界面函数
 	ScrtUSAGE_FTNRJB
}


## TODO : 测试NRJB 默认关闭selinux
#
ScrtTest01_FTNRJB(){
        local flag="disabled"
        local field="SELINUX="

        # 使用getenforce判断
        echo -n " getenforce : "
        getenforce
        getenforce | grep -q -i "${flag}"
        RetParse_FTLIB "Se 默认为 ${flag} " "False"
}


## TODO : 测试NRJB 默认关闭firewalld
#
ScrtTest02_FTNRJB(){
        local svcname="firewalld"

        # 判断是否存在svcname
        SvcExist_FTLIB "isExist" "no" "${svcname}"
        RetParse_FTLIB "存在 ${svcname} 服务" "False"

        # 判断 svcname 是否已经打开
        SvcActive_FTLIB "noActive" "no" "${svcname}"
        RetParse_FTLIB "当前未激活${svcname}服务" "False"

        # 开机不需要自启动
        SvcEnable_FTLIB "noEnable" "no" "${svcname}"
        RetParse_FTLIB "开机默认未自启动${svcname}服务" "False"
}


## TODO : Main
#  Out  : 
#         0 => TPASS
#         1 => TFAIL
#         other => TCONF
ScrtMain_FTNRJB(){
	ScrtInit_FTNRJB

	ScrtTest01_FTNRJB

	ScrtTest02_FTNRJB

	return ${TPASS}	
}

ScrtMain_FTNRJB
ScrtExit_FTNRJB $?
